<?php

namespace Api\Controller;

use Think\Controller;
use Think\Upload;
use Think\Log;
class UploadimageController extends Controller
{

//

    public function upload()
    {
        if (!IS_POST) return false;
        return self::_xhUpload($_FILES);
    }

    /**
     * xheditor专用上传
     * @param string|array $files
     * @param array $config 上传配置
     * @param string $type 上传文件类型
     */
    private function _xhUpload($files, $config = array(), $type = '')
    {
        $msg = null;
        $error = null;

        //上传配置
        $config = C('FILE_UPLOAD_CONFIG');

        $upload = new Upload($config);
        $info = $upload->uploadOne($files['fileimg']);
        if ($info) {
            $localName = $info['name'];
            $filename = UPLOAD_PATH . $info['savepath'] . $info['savename'];
            $msg = array(
                'url' => file_path2url($filename),
                'localname' => $localName
            );
        } else {
            $error = $upload->getError();
        }

        //返回上传结果
        $this->ajaxReturn(array('result' => $msg));
    }

}
